package org.acb.sgp.managedbeans;

import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.acb.sgp.beans.Estado;
import org.acb.sgp.beans.Programa;
import org.acb.sgp.service.BusinessLayerService;
import org.acb.sgp.service.impl.BusinessLayerServiceImpl;
import org.acb.sgp.utils.FacesUtil;

@ManagedBean
@ViewScoped
public class ProgramaBean implements Serializable {

	private static final long serialVersionUID = 1L;
	private final BusinessLayerService service = new BusinessLayerServiceImpl();
    private List<Programa> programas;
    private Programa programa;

    @PostConstruct
    public void init() {
        programa = new Programa();
        programas = service.listaProgramas();
    }

    public void nuevo() {
        programa = new Programa();
    }

    public void registrar() {
        Estado estado = new Estado();
        estado.setCodEstado(1);
        programa.setEstado(estado);
        service.registrarPrograma(programa);
        FacesUtil.closeDialog("registrar");
        FacesUtil.showMessage("PROGRAMA GUARDADO", FacesUtil.INFO);
        programas = service.listaProgramas();
    }

    public void eliminar(Programa pPrograma) {
        service.eliminarPrograma(pPrograma);
        FacesUtil.closeDialog("eliminar");
        FacesUtil.showMessage("PROGRAMA ELIMINADO", FacesUtil.INFO);
        programas = service.listaProgramas();
    }

    public List<Programa> getProgramas() {
        return programas;
    }

    public void setProgramas(List<Programa> programas) {
        this.programas = programas;
    }

    public Programa getPrograma() {
        return programa;
    }

    public void setPrograma(Programa programa) {
        this.programa = programa;
    }
}
